/* 步骤1 */
/* export default (state = 0, action) => {
    console.log(state, action)
    switch (action.type) {
        case 'add':
            return state + 1;
        case 'sup':
            return state - 1;
        default:
            break;
    }
    return state
} */
/* 步骤2 */
/* const initialState = {
    str: "演示redux",
} */
/*步驟3 */
const initialState = {
    str: "演示redux",
    list: [111, 222, 333]
}


export default (state = initialState, action) => {
    console.log(state, action)
    switch (action.type) {
        case 'chginput':
            let nstate = { ...state }
            nstate.str = action.data
            return nstate;
        case 'add':
            state.list.push(action.data);
            return { ...state, list: [...state.list] };
        case 'del':
            state.list.splice(action.data,1)
            return { ...state, list: [...state.list] };
        default:
            break;
    }
    return state
}

